package com.cuitrip.business.bill;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cuitrip.business.bill.model.Bills;
import com.cuitrip.business.bill.model.UserAccount;
import com.cuitrip.service.R;
import com.lab.app.customui.CustomUiConfig;
import com.lab.app.customui.CustomUiFragment;
import com.lab.rx.bus.RxBus;
import com.lab.utils.NumberUtils;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by sheena on 16/4/30.
 */
public class SubmitSucFragment extends CustomUiFragment {
    @Bind(R.id.withdraw_amount)
    TextView withdrawAmount;

    @Bind(R.id.account_no)
    TextView accountNo;

    @Bind(R.id.account_type)
    TextView accountType;

    public static final String KEY_MONEY="money";
    public static final int ACCOUNT_PAYPAL = 0;
    public static final int ACCOUNT_BANK = 1;
    private String withdrawMoney;
    private UserAccount account;

    public static SubmitSucFragment newInstance(String withdrawMoney, UserAccount account) {
        SubmitSucFragment submitSucFragment = new SubmitSucFragment();
        Bundle bundle = new Bundle();
        bundle.putString(KEY_MONEY,withdrawMoney);
        bundle.putSerializable(UserAccount.ACCOUNT_KEY,account);
        submitSucFragment.setArguments(bundle);
        return submitSucFragment;
    }
    @Override
    public boolean initCloseTopBar() {
        return true;
    }

    @Override
    public CustomUiConfig initCustomUiConfig() {
        return null;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState, R.layout.fragment_submit_suc);
        if (getArguments()!=null){
            withdrawMoney = getArguments().getString(KEY_MONEY);
            account = (UserAccount) getArguments().getSerializable(UserAccount.ACCOUNT_KEY);
        }
        return view;
    }

    @Override
    public void initView() {
        ButterKnife.bind(this,getView());
        if (!TextUtils.isEmpty(withdrawMoney)) {
            withdrawAmount.setText("$ "+NumberUtils.getMoneyFormat(withdrawMoney));
        }
        if (account!=null) {
            int type = account.getType();
            if (ACCOUNT_BANK==type){
                accountType.setText(getString(R.string.wallet_withdraw_debit_card));
            }else{
                accountType.setText(getString(R.string.wallet_account_type_paypal));
            }
            accountNo.setText(account.getAccountAbbr() + "(" + account.getAccountNumber() + ")");
        }
    }

    @OnClick(R.id.return_action)
    public void back(){
        getHostActivity().getCustomSelfFragmentManager().popBackStackImmediate(WithdrawPageFragment.class.getName(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
    }
}
